<template>
  <view class="webview-container">
    <web-view :src="url" :webview-styles="webviewStyles"></web-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      url: '',
      webviewStyles: {
        progress: {
          color: '#9370DB', // 与主题色一致
        },
      },
    }
  },
  onLoad(options) {
    console.log('WebView收到参数:', options)
    // 获取传入的url参数并解码
    if (options && options.url) {
      try {
        this.url = decodeURIComponent(options.url)
        console.log('解码后的URL:', this.url)
      } catch (error) {
        console.error('URL解码错误:', error)
        uni.showToast({
          title: 'URL解析错误',
          icon: 'none',
        })
      }
    } else {
      console.error('未接收到URL参数')
      uni.showToast({
        title: '链接无效',
        icon: 'none',
      })
      setTimeout(() => {
        uni.navigateBack()
      }, 1500)
    }
  },
}
</script>

<style>
.webview-container {
  width: 100%;
  height: 100vh;
}
</style>
